package com.wontube.smr.web.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wontube.client.remote.Remoting;
import com.wontube.smr.client.model.po.WebsiteLink;
import com.wontube.smr.web.client.m.IWebsiteLinkHandler;

@Controller
public class LinkController {	
	@RequestMapping("/about")
	public ModelAndView aboutus() {
		return new ModelAndView("about/about_us");
	}
	
	@RequestMapping("/term")
	public ModelAndView term() {
		return new ModelAndView("about/term");
	}
	
	@RequestMapping("/link") 
	public ModelAndView link(){
		Remoting<IWebsiteLinkHandler> remoting = new Remoting<IWebsiteLinkHandler>();
		IWebsiteLinkHandler handler = remoting.createService(IWebsiteLinkHandler.class);
		List<WebsiteLink> links = handler.listWontubePartnerSites();
		ModelAndView mv = new ModelAndView("about/link");
		mv.addObject("websiteList", links);
		return mv; 
	}
	
	@RequestMapping("/supportsite")
	public ModelAndView sites() {
		return new ModelAndView("about/support_sites");
	}
	
	@RequestMapping("/sitemap")
	public ModelAndView sitemap() {
		return new ModelAndView("about/sitemap");
	}
	
	@RequestMapping("/404")
	public ModelAndView error404(HttpServletRequest request) {		
		return new ModelAndView("error/404");
	}
	
	@RequestMapping("/50x")
	public ModelAndView error50x(HttpServletRequest request) {		
		return new ModelAndView("error/50x");
	}
	
	//=====301====
	@RequestMapping("/download")
	public void movieHome0(HttpServletRequest request, 
			HttpServletResponse response) throws IOException{	
		response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
		response.sendRedirect(request.getContextPath() + "/movie/");	
	}
}
